package com.example.myworkers.controller;/*
 *编写者：陆铭
 */

import com.example.myworkers.model.Role;
import com.example.myworkers.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "role")
@RestController
public class RoleController {
    @Autowired
    private IRoleService roleService;

    @ApiOperation(value = "查询所有角色信息",notes = "获取角色信息返回json字符串")
    @RequestMapping("/getRole")
    public String getRole(){
        return "Hello Role";
    }

    @CrossOrigin
    @ApiOperation(value = "对角色的添加方法")
    @GetMapping("/addRole")
    public int addRole(Role role){
        System.out.println("进入添加角色信息接口");
        return roleService.insertRole(role);
    }
    @ApiOperation(value = "对角色的修改方法")
    @GetMapping("/editRole")
    public int EditRole(@RequestBody Role role){
        System.out.println("进入添加角色信息接口");
        return roleService.insertRole(role);
    }

    @ApiOperation(value = "对角色的删除方法")
    @GetMapping("/delRole")
    public int DeleteRole(int rid){
        System.out.println("进入角色删除方法");
        int returnValue=0;
        if(rid!=0){
            Role role=new Role();
            role.setId(rid);
            returnValue=roleService.deleteRole(role);
        }
        return returnValue;
    }

    @ApiOperation(value = "对角色信息的单个查询方法")
    @GetMapping("/getOneRole")
    public Role getRole(int rid){
        Role role=new Role();
        System.out.println("进入角色单条查询方法");
        if(rid!=0){
            Role role1=new Role();
            role.setId(rid);
            role=roleService.getRole(role1);
            System.out.println("返回的数据集合为："+role.getName());
        }
        return role;
    }

}
